import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart';
import 'package:wallpaper/components/images/image_hero_one.dart';

class ImageLoadOne extends StatelessWidget {
  final String imageUrl;
  final BoxFit fit;
  final double height;

  const ImageLoadOne(
      {super.key,
      required this.imageUrl,
      this.fit = BoxFit.cover,
      this.height = 200});

  @override
  Widget build(BuildContext context) {
    return Hero(
      tag: imageUrl,
      child: GestureDetector(
        onTap: () {
          Navigator.push(
              context,
              MaterialPageRoute(
                  builder: (context) => ImageHeroOne(
                        tagId: imageUrl,
                        imageUrl: imageUrl,
                      )));
        },
        child: CachedNetworkImage(
          height: height,
          width: double.infinity,
          imageUrl: imageUrl,
          fit: fit,
          progressIndicatorBuilder: (context, url, downloadProgress) {
            //显示loading效果
            return Center(
              child: SizedBox(
                width: 20,
                height: 20,
                child: CircularProgressIndicator(
                  strokeWidth: 2,
                ),
              ),
            );
          },
          errorWidget: (context, url, error) => Icon(
            Icons.perm_media,
            color: Theme.of(context).colorScheme.primaryContainer,
            size: 50,
          ),
        ),
      ),
    );
  }
}
